﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using hedefgrup.reports.renault.database;

namespace hedefgrup.reports.common.SSRD
{
    public class Report_SSRD_Standard : Report_Standard
    {
        protected override void SetCriteriaList()
        {
            Criterias.Add(new Criteria_SSRD_SSMPeriod() { Context = Context });
            Criterias.Add(new Criteria_Roll() { Context = Context });
            Criterias.Add(new Criteria_BeginMonth() { Context = Context });
            Criterias.Add(new Criteria_EndMonth() { Context = Context });
            Criterias.Add(new Criteria_SSRD_Organization() { Context = Context });
        }

        public override ReportResult GenerateReport()
        {
            ReportResult results = new ReportResult(this);

            AppendQuestion("S2a", results);
            AppendQuestion("S5_S7a", results);
            AppendQuestion("S3", results);
            AppendQuestion("BO_MEMNUNIYET", results);
            AppendQuestion("S3f", results);
            AppendQuestion("S6", results);
            AppendQuestion("S10", results);

            return results;
        }

        protected override DataTable GetYearlyReportData(string questionCode, string caseStatement)
        {
            Filter yearFilter = GetFilterByName("YIL");
            string yearFilterValueBackup = yearFilter.Values.Count > 0 ? yearFilter.Values[0] : null;
            yearFilter.Values.Clear();
            // yearFilter.Values.Add(GetMaxYearForYearlyTotal().ToString());

            DataTable yearlyData = db.query
            (
                "SELECT YIL = 1, AY = 0, CNT = COUNT(*), " + questionCode + (caseStatement != null ? " = " + caseStatement : "") + " FROM " + Context.TableName + " " +
                GetSqlStatementFilter(new Criteria[] { }) +
                " GROUP BY " + (caseStatement != null ? caseStatement : questionCode),
                base.GetSqlStatementParameters(new Criteria[] { })
            );

            if (yearFilterValueBackup != null)
            {
                yearFilter.Values[0] = yearFilterValueBackup;
            }
            //else
            //{
            //    yearFilter.Values.Clear();
            //}
            return yearlyData;
        }

        protected override string GetYearlyTotalColumnHeader()
        {
            return "Kümüle";
        }

        public override bool SupportsProject(string projectName)
        {
            return projectName == Global.PROJECT_SSRD;
        }

        public override string SortPrefix
        {
            get
            {
                return "SSRD_01";
            }
        }
    }
}
